const mysql = require("mysql2");
const service = {
  // 查找是否有这个用户
  find(username, password) {
    try {
      const promisePool = mysql.createPool(getDBconfig()).promise();
      return promisePool.query(
        `select username from user where username=? and password=?`,
        [username, password]
      );
    } catch (error) {
      return [];
    }
  },
};
module.exports = service;
function getDBconfig() {
  return {
    host: "127.0.0.1",
    user: "root",
    port: 3306,
    password: "",
    database: "chat",
    connectionLimit: 1,
  };
}
